﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.MockConnector.Repositories
{
	public class CatalogRepository
	{
		public IEnumerable<Models.ProductCategory> GetAllCategories()
		{
			yield return new Models.ProductCategory()
			{
				Code = "Laptops",
				PageDescription = "Laptops",
				Id = 1,
				IsForefront = true,
				Keywords = "Laptops",
				Link = "laptops",
				Name = "Laptops",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Laptop Accessories",
				PageDescription = "Laptop Accessories",
				Id = 2,
				IsForefront = true,
				Keywords = "Laptop, Accessories",
				Link = "laptop_accessories",
				Name = "Laptop Accessories",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Desktop Computers",
				PageDescription = "Desktop Computers",
				Id = 3,
				IsForefront = true,
				Keywords = "Desktop, Computers",
				Link = "desktop_computers",
				Name = "Desktop Computers",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Apple",
				PageDescription = "Apple",
				Id = 4,
				IsForefront = true,
				Keywords = "Apple",
				Link = "apple",
				Name = "Apple",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Monitors",
				PageDescription = "Monitors",
				Id = 5,
				IsForefront = true,
				Keywords = "Monitors",
				Link = "monitors",
				Name = "Monitors",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Printers",
				PageDescription = "Printers",
				Id = 6,
				IsForefront = true,
				Keywords = "Printers",
				Link = "printers",
				Name = "Printers",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Drives & Storage",
				PageDescription = "Drives & Storage",
				Id = 7,
				IsForefront = true,
				Keywords = "Drives, Storage",
				Link = "drives_storage",
				Name = "Drives & Storage",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Networking",
				PageDescription = "Networking",
				Id = 8,
				IsForefront = true,
				Keywords = "Networking",
				Link = "networking",
				Name = "Networking",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Software",
				PageDescription = "Software",
				Id = 9,
				IsForefront = true,
				Keywords = "Software",
				Link = "software",
				Name = "Software",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Computer Upgrades",
				PageDescription = "Computer Upgrades",
				Id = 10,
				IsForefront = true,
				Keywords = "Computer, Upgrades",
				Link = "computer_upgrades",
				Name = "Computer Upgrades",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Computer Speakers",
				PageDescription = "Computer Speakers",
				Id = 11,
				IsForefront = true,
				Keywords = "Computer, Speakers",
				Link = "computer_speakers",
				Name = "Computer Speakers",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Mice & Keyboards",
				PageDescription = "Mice & Keyboards",
				Id = 12,
				IsForefront = true,
				Keywords = "Mice,Keyboards",
				Link = "mice_and_keyboards",
				Name = "Mice & Keyboards",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Webcams",
				PageDescription = "Webcams",
				Id = 13,
				IsForefront = true,
				Keywords = "Webcams",
				Link = "webcams",
				Name = "Webcams",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Computer Accessories",
				PageDescription = "Computer Accessories",
				Id = 14,
				IsForefront = true,
				Keywords = "Computer, Accessories",
				Link = "computer_accessories",
				Name = "Computer Accessories",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Media",
				PageDescription = "Media",
				Id = 15,
				IsForefront = true,
				Keywords = "Media",
				Link = "media",
				Name = "Media",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Projects",
				PageDescription = "Projects",
				Id = 16,
				IsForefront = true,
				Keywords = "Projects",
				Link = "projects",
				Name = "Projects",
				ProductCount = 0,
			};

			yield return new Models.ProductCategory()
			{
				Code = "Scanners",
				PageDescription = "Scanners",
				Id = 17,
				IsForefront = true,
				Keywords = "Scanners",
				Link = "scanners",
				Name = "Scanners",
				ProductCount = 0,
			};

			yield break;
		}

		public IEnumerable<Models.Brand> GetAllBrands()
		{ 
			yield return new ERPStore.Models.Brand()
				{
					ExternalBrandLink = "http://www.microsoft.com",
					Id = 1,
					Link = "microsoft",
					Name = "Microsoft",
					PageDescription = "Microsoft",
					Keywords = "Microsoft",
					PageTitle = "Micrososft",
				};

			yield return new ERPStore.Models.Brand()
				{
					ExternalBrandLink = "http://www.logitech.com",
					Id = 2,
					Link = "logitech",
					Name = "Logitech",
					PageDescription = "Logitech",
					Keywords = "Logitech",
					PageTitle = "Logitech",
				};

			yield return new ERPStore.Models.Brand()
			{
				ExternalBrandLink = "http://www.sony.com",
				Id = 3,
				Link = "sony",
				Name = "sony",
				PageDescription = "Sony",
				Keywords = "Sony",
				PageTitle = "Sony",
			};

			yield break;
		}

		public IEnumerable<Models.Product> GetAllProducts()
		{
			var defaultCategory = GetAllCategories().First();
			yield return new ERPStore.Models.Product
				{
					Brand = GetAllBrands().First(),
					ManufacturerUrl = "",
					Category = defaultCategory,
					Code = "XBOX360",
					CreationDate = DateTime.Now,
					DefaultImage = new ERPStore.Models.Media()
					{
						ExternalUrl = null,
						Id = "1",
						LastUpdate = DateTime.Now,
						MimeType = "image/jpg",
						Url = "/content/images/xbox360-2.jpg"
					},
					DefaultTaxRate = 0.196,
					Id = 1,
					Keywords = "xbox, 360",
					Link = "Xbox_360_Arcade",
					LongDescription = "The Xbox 360 Arcade console is everything you need to hit the ground running. Plug in the console and connect the wireless controller and you're playing.",
					MinimumSaleQuantity = 1,
					OrderCount = 5,
					Packaging = new ERPStore.Models.Packaging() { Value = 1 },
					PageDescription = "xbox360",
					PageTitle = "XBOX 360",
					SalePrice = new ERPStore.Models.Price(199.99, 0.196),
					SaleUnitValue = 1,
					ShortDescription = "The Xbox 360 Arcade console is everything you need",
					StrengthsPoints = null,
					Title = "Xbox 360 Arcade",
					Weight = 150,
					Metric = Models.Metric.Unit,
				};

			yield return new ERPStore.Models.Product
				{
					Brand = GetAllBrands().First(),
					ManufacturerUrl = "",
					Category = defaultCategory,
					Code = "XBOXWC",
					CreationDate = DateTime.Now,
					DefaultImage = new ERPStore.Models.Media()
					{
						ExternalUrl = null,
						Id = "2",
						LastUpdate = DateTime.Now,
						MimeType = "image/jpg",
						Url = "/content/images/Xbox360WirelessController2.jpg"
					},
					DefaultTaxRate = 0.196,
					Id = 2,
					Keywords = "xbox, wireless, controller",
					Link = "Xbox_360_Wireless_Controller",
					LongDescription = "High-performance wireless gaming now comes in black! Using optimized technology, the black Xbox 360 Wireless Controller lets you enjoy a 30-foot range and up to 40 hours of life on the two included AA batteries.",
					MinimumSaleQuantity = 1,
					OrderCount = 5,
					Packaging = new ERPStore.Models.Packaging() { Value = 1 },
					PageDescription = "xbox360",
					PageTitle = "Xbox 360 Wireless controller",
					SalePrice = new ERPStore.Models.Price(49.99, 0.196),
					SaleUnitValue = 1,
					ShortDescription = "High-performance wireless gaming now comes in black!",
					StrengthsPoints = null,
					Title = "Xbox 360 Wireless controller",
					Weight = 150,
					Metric = Models.Metric.Unit,
				};

			yield return new ERPStore.Models.Product
			{
				Brand = GetAllBrands().First(),
				ManufacturerUrl = "",
				Category = defaultCategory,
				Code = "DUPTITLE",
				CreationDate = DateTime.Now,
				DefaultImage = new ERPStore.Models.Media()
				{
					ExternalUrl = null,
					Id = "2",
					LastUpdate = DateTime.Now,
					MimeType = "image/jpg",
					Url = "/content/images/Xbox360WirelessController.jpg"
				},
				DefaultTaxRate = 0.196,
				Id = 3,
				Keywords = "xbox, wireless, controller",
				Link = "Xbox_360_Wireless_Controller",
				LongDescription = null,
				MinimumSaleQuantity = 1,
				OrderCount = 5,
				Packaging = new ERPStore.Models.Packaging() { Value = 1 },
				PageDescription = "xbox360",
				PageTitle = "Xbox 360 Wireless controller",
				SalePrice = new ERPStore.Models.Price(72.00, 0.196),
				SaleUnitValue = 1,
				ShortDescription = "Xbox 360 Wireless Controller",
				StrengthsPoints = null,
				Title = "Xbox 360 Wireless controller",
				Weight = 150,
				Metric = Models.Metric.Unit,
			};


			yield return new ERPStore.Models.Product
			{
				Brand = GetAllBrands().ElementAt(1),
				ManufacturerUrl = "",
				Category = defaultCategory,
				Code = "VARIATION1",
				CreationDate = DateTime.Now,
				DefaultImage = new ERPStore.Models.Media()
				{
					ExternalUrl = null,
					Id = "1",
					LastUpdate = DateTime.Now,
					MimeType = "image/jpg",
					Url = "/content/images/xbox360.jpg"
				},
				DefaultTaxRate = 0.196,
				Id = 4,
				Keywords = "variation",
				Link = "Variation_1",
				LongDescription = "The first variation.",
				MinimumSaleQuantity = 1,
				OrderCount = 3,
				Packaging = new ERPStore.Models.Packaging() { Value = 1 },
				PageDescription = "Variation 1",
				PageTitle = "Variation 1",
				SalePrice = new ERPStore.Models.Price(0.0, 0.196),
				SaleUnitValue = 1,
				ShortDescription = "Variation 1",
				StrengthsPoints = null,
				Title = "Variation 1",
				Weight = 150,
				Metric = Models.Metric.Unit,
				IsParentVariation = true,
			};

			yield return new ERPStore.Models.Product
			{
				Brand = GetAllBrands().ElementAt(1),
				ManufacturerUrl = "",
				Category = GetAllCategories().ElementAt(2),
				Code = "VARIANT1",
				CreationDate = DateTime.Now,
				DefaultImage = new ERPStore.Models.Media()
				{
					ExternalUrl = null,
					Id = "1",
					LastUpdate = DateTime.Now,
					MimeType = "image/jpg",
					Url = "/content/images/variant1.jpg"
				},
				DefaultTaxRate = 0.196,
				Id = 5,
				Keywords = "variation",
				Link = "Variant_1",
				LongDescription = "The variant 1.",
				MinimumSaleQuantity = 1,
				OrderCount = 3,
				Packaging = new ERPStore.Models.Packaging() { Value = 1 },
				PageDescription = "Variant 1",
				PageTitle = "Variant 1",
				SalePrice = new ERPStore.Models.Price(10.0, 0.196),
				SaleUnitValue = 1,
				ShortDescription = "variant 1",
				StrengthsPoints = null,
				Title = "variant 1",
				Weight = 15,
				Metric = Models.Metric.Unit,
				VariationProductParentId = 4,
			};

			yield return new ERPStore.Models.Product
			{
				Brand = GetAllBrands().ElementAt(1),
				ManufacturerUrl = "",
				Category = GetAllCategories().ElementAt(2),
				Code = "VARIANT2",
				CreationDate = DateTime.Now,
				DefaultImage = new ERPStore.Models.Media()
				{
					ExternalUrl = null,
					Id = "variant2",
					LastUpdate = DateTime.Now,
					MimeType = "image/jpg",
					Url = "/content/images/variant2.jpg"
				},
				DefaultTaxRate = 0.196,
				Id = 6,
				Keywords = "variation",
				Link = "Variant_2",
				LongDescription = "The variant 2.",
				MinimumSaleQuantity = 1,
				OrderCount = 3,
				Packaging = new ERPStore.Models.Packaging() { Value = 1 },
				PageDescription = "Variant 2",
				PageTitle = "Variant 2",
				SalePrice = new ERPStore.Models.Price(12.0, 0.196),
				SaleUnitValue = 1,
				ShortDescription = "variant 2",
				StrengthsPoints = null,
				Title = "variant 2",
				Weight = 55,
				Metric = Models.Metric.Unit,
				VariationProductParentId = 4,
			};

			var sonyBrand = GetAllBrands().Where(brand => brand.Name == "sony").Single();
			yield return new ERPStore.Models.Product
			{
				Brand = sonyBrand,
				ManufacturerUrl = "http://www.sony.com",
				Category = defaultCategory,
				Code = "PS3",
				CreationDate = DateTime.Now,
				DefaultImage = new ERPStore.Models.Media()
				{
					ExternalUrl = null,
					Id = "10",
					LastUpdate = DateTime.Now,
					MimeType = "image/jpg",
					Url = "/content/images/ps3.jpg"
				},
				DefaultTaxRate = 0.196,
				Id = 10,
				Keywords = "ps3, play station",
				Link = "play_station_3",
				LongDescription = "The fourth generation of hardware released for the PlayStation 3 entertainment platform, the PlayStation 3 160GB system is the next stage in the evolution of Sony's console gaming powerhouse. Loaded with a mix of multimedia features and functions available on earlier PlayStation 3 models, as well as a series of new advancements and refinements, the PlayStation 3 160GB system is destined to push the envelope in the realm of Next-Generation entertainment.",
				MinimumSaleQuantity = 1,
				OrderCount = 10,
				Packaging = new ERPStore.Models.Packaging() { Value = 1 },
				PageDescription = "Playstation 3 Slim 160GB by Sony",
				PageTitle = "Playstation 3 Slim 160GB : Sony",
				SalePrice = new ERPStore.Models.Price(147.60, 0.196),
				SaleUnitValue = 1,
				ShortDescription = "With the PlayStation 3 160GB system, you get free PlayStation Network membership, built-in Wi-Fi and 160GB of hard disk drive storage for games, music, videos and photos.",
				StrengthsPoints = "The PS3 is a great system. Easy to use, futuristic on-screen interface, quality sleek hardware, awesome graphics, lots of benefits.",
				Title = "Sony Playstation 3 Slim 160GB",
				Weight = 150,
				Metric = Models.Metric.Unit,
			};

			yield return new ERPStore.Models.Product
			{
				Brand = GetAllBrands().First(),
				ManufacturerUrl = "",
				Category = defaultCategory,
				Code = "XBOXWH1",
				CreationDate = DateTime.Now,
				DefaultImage = new ERPStore.Models.Media()
				{
					ExternalUrl = null,
					Id = "Xboxwheel",
					LastUpdate = DateTime.Now,
					MimeType = "image/jpg",
					Url = "/content/images/Xboxwheel.jpg"
				},
				DefaultTaxRate = 0.196,
				Id = 11,
				Keywords = "wheel",
				Link = "Xbox_360_Wheel_Controller",
				LongDescription = "Race to victory with Mad Catz' officially Microsoft licensed Wired Racing Wheel for Xbox 360. The most realistic racing wheel available for the Xbox 360. Wrap your hands around the rubber-grip wheel, extend the retractable leg supports, drop your foot onto the pedal and hang on. Vibration feedback adds to the realism. With ten analog action buttons, you can take the Wired Mad Catz Racing Wheel to Talladega, Le Mans and a no-holds-barred desert rally, all in the same afternoon. Officially licensed for Xbox 360.",
				MinimumSaleQuantity = 1,
				OrderCount = 10,
				Packaging = new ERPStore.Models.Packaging() { Value = 1 },
				PageDescription = "xbox360",
				PageTitle = "Xbox 360 Wireless controller : Microsoft",
				SalePrice = new ERPStore.Models.Price(45.05, 0.196),
				SaleUnitValue = 1,
				ShortDescription = "The MC2 Racing Wheel by Mad Catz for the XBOX 360 does have pedals. I'm not sure what the previous reviewer was playing on.",
				StrengthsPoints = "I'm sure future driving/racing games will allow more customization for this wheel.",
				Title = "Xbox 360 Wired Racing Wheel",
				Weight = 150,
				Metric = Models.Metric.Unit,
			};

			yield return new ERPStore.Models.Product
			{
				Brand = GetAllBrands().First(),
				ManufacturerUrl = "",
				Category = defaultCategory,
				Code = "B004J3V90Y",
				CreationDate = DateTime.Now,
				DefaultImage = new ERPStore.Models.Media()
				{
					ExternalUrl = "http://ecx.images-amazon.com/images/I/71hurE69ltL._SL1000_.jpg",
					Id = "B004J3V90Y",
					LastUpdate = DateTime.Now,
					MimeType = "image/jpg",
					Url = "http://ecx.images-amazon.com/images/I/71hurE69ltL._SL1000_.jpg"
				},
				DefaultTaxRate = 0.196,
				Id = 12,
				Keywords = "camera",
				Link = "Canon_Rebel_T3i_18_MP_CMOS_Digital_SLR_Camera",
				LongDescription = @"High Resolution Still Capture
18.0 Megapixel CMOS (APS-C) sensor and DIGIC 4 Image Processor for high image quality and speed. 
The EOS Rebel T3i has an 18.0 Megapixel CMOS (Complementary Metal Oxide Semiconductor) sensor that captures images with exceptional clarity and tonal range and offers more than enough resolution for big enlargements or crops. This first-class sensor features many of the same new technologies as used by professional Canon cameras to maximize each pixel’s light-gathering efficiency. Its APS-C size sensor creates an effective 1.6x field of view (compared to 35mm format).",
				MinimumSaleQuantity = 1,
				OrderCount = 10,
				Packaging = new ERPStore.Models.Packaging() { Value = 1 },
				PageDescription = "Canon has unveiled the EOS T3i (known in Europe as the EOS 600D) upper entry-level DSLR. It continues to use the 18MP CMOS sensor seen in the Rebel T2i (550D) but gains a tilt and swivel 1,040k dot LCD monitor like the one offered on the more expensive 60D.",
				PageTitle = "Rebel T3i 18 MP CMOS Digital SLR Camera and DIGIC 4 Imaging with EF-S 18-55mm f/3.5-5.6 IS Lens : Canon EOS",
				SalePrice = new ERPStore.Models.Price(499.00, 0.196),
				SaleUnitValue = 1,
				ShortDescription = "The Canon 5169B003 includes the EOS Rebel T3i Digital SLR Camera and EF-S 18-55mm f/3.5-5.6 IS type II Lens. This camera and lens will help photographers who are looking for an easy-to-use camera to create their next masterpiece. The next in a long line of phenomenal compact DSLRs, the EOS Rebel T3i continues the Rebel tradition of easy operation, compact design and no-compromise performance.",
				StrengthsPoints = "Let me just say excellent professional looking shots are pretty easy with this camera, and I highly recommend it to anyone thinking of purchasing an SLR camera.",
				Title = "Canon EOS Rebel T3i",
				Weight = 150,
				Metric = Models.Metric.Unit,
			};

			yield break;
		}

		public Models.ProductVariation GetProductVariationListByProductId(int productId)
		{
			var variationProduct = GetAllProducts().SingleOrDefault(i => i.Id == productId);
			if (variationProduct == null)
			{
				return null;
			}

			var result = new Models.ProductVariation();

			var productList = GetAllProducts().Where(i => i.VariationProductParentId == productId);

			result.Columns.Add(new System.Data.DataColumn("ProductCode", typeof(string)));
			result.Columns.Add(new System.Data.DataColumn("ProductTitle", typeof(string)));
			result.Columns.Add(new System.Data.DataColumn("SalePrice", typeof(decimal)));
			result.Columns.Add(new System.Data.DataColumn("IsDefault", typeof(bool)));

			int def = 0;
			foreach (var product in productList)
			{
				var row = result.NewRow();
				result.Rows.Add(row);
				row["ProductCode"] = product.Code;
				row["ProductTitle"] = product.Title;
				row["SalePrice"] = product.SalePrice.Value;

				row["IsDefault"] = ++def == 0;

				var variationList = GetVariationList();

				foreach (var variation in variationList)
				{
					if (!result.Columns.Contains(variation.VariationName))
					{
						result.Columns.Add(new System.Data.DataColumn(variation.VariationName, typeof(string)));
					}
					row[variation.VariationName] = variation.Value.ToString();
				}
			}

			return result;
		}

		private IEnumerable<Models.VariationValue> GetVariationList()
		{
			yield return new Models.VariationValue()
			{
				Type = Models.VariationType.Text,
				Value = "ABC",
				VariationName = "Size"
			};

			yield return new Models.VariationValue()
			{
				Type = Models.VariationType.Text,
				Value = "DEF",
				VariationName = "Size"
			};

			yield break;
		}

		public IEnumerable<Models.ProductStockInfo> GetAllProductStockInfo()
		{
			var products = GetAllProducts();

			foreach (var product in products)
			{
				yield return new Models.ProductStockInfo()
				{
					ProductCode = product.Code,
					DeliveryDaysCount = 2,
					MinimalQuantity = product.MinimumSaleQuantity,
					MostProvisionningDate = null,
					PhysicalStock = product.MinimumSaleQuantity,
					ProvisionnedQuantity = 0,
					ProvisionningDaysCount = 2,
					ReservedQuantity = 0,
				};
			}

			yield break;
		}
	}
}
